# (x-2)^2 = 4
from tqdm import trange

epoch = 100
lr = 0.01
x = 3  # 初始值
label = 4

for e in trange(epoch):

    pre = (x - 2) ** 2  # 预测值
    loss = (pre - label) ** 2  # 计算损失

    delta_x = 2 * (pre - label) * 2 * (x - 2)  # 复合函数求导
    x = x - delta_x * lr  # 乘以学习率

print(x)
